package com.whfc.ms.api.emp.controller;

import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppEmpHealthReportDTO;
import com.whfc.emp.param.EmpHealthInfoAddParam;
import com.whfc.emp.param.EmpHealthInfoEditParam;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsAppEmpHealthReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021-09-02 14:20
 */
@RestController
@RequestMapping("/ms/api/emp/health/report")
public class AppEmpHealthReportController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsAppEmpHealthReportService msAppEmpHealthReportService;


    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("empId") Integer empId,
                       @RequestParam("type") String type,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize) {
        logger.info("获取防疫信息列表，loginer:{},empId:{}, type:{}, pageNum:{}, pageSize:{}", user.getUsername(), empId, type, pageNum, pageSize);
        PageData<AppEmpHealthReportDTO> pageData = msAppEmpHealthReportService.list(empId, type, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }


    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @Validated @RequestBody EmpHealthInfoAddParam param) {
        logger.info("添加防疫信息，loginer:{},param:{}", user.getUsername(), param);
        msAppEmpHealthReportService.add(param);
        return ResultUtil.success();
    }


    @PostMapping("/edit")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @Validated @RequestBody EmpHealthInfoEditParam param) {
        logger.info("修改防疫信息，loginer:{},param:{}", user.getUsername(), param);
        msAppEmpHealthReportService.edit(param);
        return ResultUtil.success();
    }


    @PostMapping("/del/{healthReportId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("healthReportId") Integer healthReportId) {
        logger.info("删除防疫信息，loginer:{},healthReportId:{}", user.getUsername(), healthReportId);
        msAppEmpHealthReportService.del(healthReportId);
        return ResultUtil.success();
    }


    @PostMapping("/upload/img")
    public Result uploadImg(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                            @RequestParam("file") MultipartFile file) {
        logger.info("上传防疫信息图片，loginer:{}", user.getUsername());
        OssPathDTO ossPathDTO = msAppEmpHealthReportService.uploadImg(file);
        return ResultUtil.success(ossPathDTO);
    }


}
